package cn.qingyun.gis.modules.enterprise.aggregate.service.impl;


import cn.qingyun.gis.exception.CommonException;
import cn.qingyun.gis.modules.enterprise.aggregate.feign.GovernmentClientService;
import cn.qingyun.gis.modules.enterprise.aggregate.request.AggregateRequest;
import cn.qingyun.gis.modules.enterprise.aggregate.request.BuildInfoVo;
import cn.qingyun.gis.modules.enterprise.aggregate.request.BuildRequest;
import cn.qingyun.gis.modules.enterprise.aggregate.response.AggregationVo;
import cn.qingyun.gis.modules.enterprise.aggregate.service.AggregateService;
import cn.qingyun.gis.modules.enterprise.service.IGridService;
import cn.qingyun.gis.modules.enterprise.service.IPermissionsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * @author wz
 * @version JDK 8
 * @className AggregateServiceImpl (此处以class为例)
 * @date 2024/10/29
 * @description
 */
@Slf4j
@Service
public class AggregateServiceImpl implements AggregateService {
    @Resource
    private GovernmentClientService governmentClientService;
    @Resource
    private IPermissionsService iPermissionsService;
    @Resource
    private IGridService gridService;

    @Override
    public List<AggregationVo> getAggregateList(AggregateRequest request) {
        List regionList = gridService.getRegionList();
        if (Objects.isNull(regionList)){
            throw new CommonException("获取用户权限失败");
        }
        log.info("regionList:{}",regionList);
        if (request.getLevel()==null){
            return governmentClientService.getAggregateList(request);
        } else {
            throw new CommonException("暂不支持该聚合层级");
        }
    }

    @Override
    public BuildInfoVo getDetail(BuildRequest request) {
        BigDecimal lbLat = request.getLbLat();
        BigDecimal lbLon = request.getLbLon();
        BigDecimal rtLat = request.getRtLat();
        BigDecimal rtLon = request.getRtLon();
        //首先
        return governmentClientService.getBuildInfoDetail(request.getPoiId());//获取建筑信息
    }

    @Override
    public Object getStaticInfo(AggregateRequest request) {
        return null;
    }

    @Override
    public Object exportAggStatic(AggregateRequest request) {
        return null;
    }

    private String determineAggregationLevel(int mapLevel) {
        if (mapLevel < 7) {
            return "province";
        } else if (mapLevel < 11) {
            return "city";
        } else if (mapLevel < 16) {
            return "district";
        } else {
            return "grid";
        }
    }
}
